package com.fpx.metadata.service.impl;

import com.fpx.metadata.bean.po.DbInfo;
import com.fpx.metadata.constant.SecretKeyConstant;
import com.fpx.metadata.service.DbInfoService;
import com.fpx.metadata.tool.EnDecryptUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

/**
 * @author caowei
 */
@Service
@Log4j2
public class DbInfoServiceImpl extends BaseServiceImpl<DbInfo> implements DbInfoService {

    @Override
    public Integer saveSelect(DbInfo dbInfo) {
        String password = dbInfo.getPassword();
        try {
            String encrypt = new EnDecryptUtil(SecretKeyConstant.DB_INFO_KEY + dbInfo.getHost() + dbInfo.getUser()).encrypt(password);
            dbInfo.setPassword(encrypt);
        } catch (Exception e) {
            log.error("加密失败");
            return 0;
        }
        return super.saveSelect(dbInfo);
    }
}
